<template>
  <el-dialog
    :title="state.title"
    v-model="state.dialogVisible"
    width="70%"
    :before-close="dialogBeforeClose"
    @opened="openDiag"
  >
    <div class="map-container">
      <el-tabs type="border-card">
        <el-tab-pane label="计算成果信息" lazy> <resultInfo ref="resultInfoRef" /></el-tab-pane>
        <el-tab-pane label="基础属性信息"><baseInfo /></el-tab-pane>
      </el-tabs>
    </div>
  </el-dialog>
</template>
<script setup>
import { ref, reactive, onMounted, defineExpose, nextTick } from 'vue'
import emitter from '@/utils/bus'

import resultInfo from './cpns/resultInfo.vue'
import baseInfo from './cpns/baseInfo.vue'
import { getCountResult, getCcResult } from '@/services/modules/compute-methods'
import {
  // 计算成果
  getManualSchemesresult
} from '@/services/modules/dispatch-manage'
const resultInfoRef = ref(null)
const state = reactive({
  dialogVisible: false,
  title: '基础信息'
})
defineExpose({ openMapInfo })
function openMapInfo(val) {
  nextTick(() => {
    emitter.emit('initEcharts')
  })
  state.dialogVisible = true
  state.title = val.blknm
  if (val?.dispatch) {
    getManualSchemesresult({ scid: val.id, blkcd: val.blkcd }).then((res) => {
      if (res.code === 200) {
        if (res.data.length) {
          let arr = []
          arr = res.data.map((item) => {
            return { ...item, result: [{ ccResult: item.ccResult, warnInfo: item.warnInfo }] }
          })
          state.servers = arr
          resultInfoRef.value.handleOpenModal({
            servers: state.servers,
            dispatch: val?.dispatch
            // eigResultArr: state.eigResultArr
          })
        }
      }
    })
  }
  if (val.areaRiver == 'first') {
    getCountResult({ ccid: val.id, blkcd: val.blkcd }).then((res) => {
      if (res.code === 200 && res.data) {
        state.servers = res.data[0].result
        state.servers = state.servers.map((item) => {
          return { ...item, ...res.data[0].info, scName: item.scInfo.sc_name }
        })
        state.eigResultArr = res.data[0].result
        resultInfoRef.value.handleOpenModal({
          servers: state.servers,
          eigResultArr: state.eigResultArr
        })
        // state.ccBaseInfo = res.data[0].info
      }
    })
  } else if (val.areaRiver == 'second') {
    getCcResult({ ccid: val.id, blkcd: val.blkcd }).then((res) => {
      if (res.code === 200 && res.data) {
        state.servers = res.data[0].result

        state.servers = state.servers.map((item) => {
          return { ...item, ...res.data[0].info, scName: item.scInfo.sc_name }
        })
        state.eigResultArr = res.data[0].result
        resultInfoRef.value.handleOpenModal({
          servers: state.servers,
          eigResultArr: state.eigResultArr
        })
        // state.ccBaseInfo = res.data[0].info
      }
    })
  }
}
const emit = defineEmits(['dialogClose'])
// 关闭弹框的回调
function dialogBeforeClose() {
  state.dialogVisible = false
  // emitter.emit('clearEcharts')
  emit('dialogClose')
}
const openDiag = () => {
  nextTick(() => {
    emitter.emit('initEcharts')
  })
}
</script>
<style lang="less" scoped>
.map-container {
  height: 600px;
  :deep(.el-tabs) {
    height: 100%;
    .el-tabs__content {
      height: calc(100% - 55px);
      .el-tab-pane {
        height: 100%;
      }
    }
  }
}
</style>
